cmake_minimum_required(VERSION 3.2)         # CMAKE最低版本要求

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)       # 生成 compile_commands.json 文件，方便使用一些工具（如clangd）进行代码补全和分析

set(CMAKE_SYSTEM_NAME Linux)                # 目标系统
set(CMAKE_SYSTEM_PROCESSOR arm)
set(tools /usr/local/arm/gcc-linaro-6.3.1-2017.02-x86_64_arm-linux-gnueabihf)
set(CMAKE_C_COMPILER ${tools}/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/arm-linux-gnueabihf-g++)

set(CMAKE_C_STANDARD 99)                    # 设置C标准为C99
set(CMAKE_CXX_STANDARD 11)                  # 设置C++标准为C++11

project(test_program)                       # 项目名

set(CMAKE_BUILD_TYPE "Debug")               # 默认是Release模式，设置为Debug才能调试

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build/bin) # 设置生成的可执行文件的输出目录为项目根目录下的bin目录

add_definitions(                            # 添加全局定义
    # -DUSE_MONITOR=1
    # -DUSE_MOUSE=1
    # -DUSE_SIMULATOR=1
)

file(GLOB_RECURSE MAIN_SRC
    "${PROJECT_SOURCE_DIR}/main_fn/make_for_arm/main.c"
)
file(GLOB TEST_SRC
    # v4l2库测试
    "${PROJECT_SOURCE_DIR}/bsp/bsp_v4l2.c"
    "${PROJECT_SOURCE_DIR}/mid/mid_camera.c"
)
add_executable(${PROJECT_NAME}              # 定义可执行目标(打包运行文件)
    ${MAIN_SRC}
    ${TEST_SRC}
)

target_include_directories(${PROJECT_NAME}  # 添加包含目录
    PRIVATE                                 # 私有的
    # ${PROJECT_SOURCE_DIR}                   # 项目根目录
    # debug
    ${PROJECT_SOURCE_DIR}/lib/debug
    # ......
    ${PROJECT_SOURCE_DIR}/bsp
    ${PROJECT_SOURCE_DIR}/mid
)

find_library(CURL_LIBRARIES NAMES libcurl.so PATHS lib/curl/)                       # 添加 curl 库
if(NOT CURL_LIBRARIES)
    message(FATAL_ERROR "curl not found")
endif()

target_link_libraries(${PROJECT_NAME}       # 将多个库链接到可执行文件中
    PRIVATE                                 # 私有的
    pthread                                 # pthread库
    ${CURL_LIBRARIES}                       # curl 库
)
